class MsgEnvQ{
        private:
                MsgEnv * head;
                MsgEnv * tail;
                int size;
        public:
        MsgEnvQ(){head=tail=0;size=0;};
        MsgEnvQ(int NumOfNode);
        ~MsgEnvQ(){delete [] head, tail, size;};
        void enqueue(MsgEnv * newMsgEnv);
        MsgEnv * dequeue();
        int getsize();//count number of nodes in the queue
};

MsgEnvQ::MsgEnvQ(int NumOfNodes){
    head=tail=0;
    size=0;
    if (NumOfNodes>0){
        MsgEnv *cur;
        cur=new MsgEnv;
        head=tail=cur;
        cur->next=0;
        size++;
        while (size<NumOfNodes){
            cur=new MsgEnv;
            tail->next=cur;
            tail=cur;
            cur->next=0;
            size++; 
        }
    }    
}

void MsgEnvQ::enqueue(MsgEnv * newNode){
         if (size==0)
         {head=newNode;tail=newNode;size++;return;}
         tail->next=newNode;
         tail=newNode;	  
         newNode->next=0;
        size++;
        //cout << "enqueue!";
        return;
}

MsgEnv * MsgEnvQ::dequeue(){
	MsgEnv * temp;
	if (this->size == 0|| this->head==0){
		//cout << "its empty !";
		return 0;
	}		
	temp=head;
	head=temp->next;
	temp->next=0;
	size--;
	//cout << "dequeue!";
	return temp;
}

int MsgEnvQ::getsize(){//count number of nodes in the queue
		return size;
}


class PCBQ{
        private:
                PCB * head;
                PCB * tail;
                int size;
        public:
        PCBQ(){head=tail=0;size=0;};
        //PCBQ(int NumOfNode);
        ~PCBQ(){delete [] head, tail, size;};
        void enqueue(PCB * newPCB);
        PCB * dequeue();
        int getsize();//count number of nodes in the queue
};

void PCBQ::enqueue(PCB * newNode){
         if (size==0)
         {head=newNode;tail=newNode;size++;return;}
         tail->next=newNode;
         tail=newNode;	  
         newNode->next=0;
        size++;
        //cout << "enqueue!";
        return;
}

PCB * PCBQ::dequeue(){
	PCB * temp;
	if (this->size == 0|| this->head==0){
		//cout << "its empty !";
		return 0;
	}		
	temp=head;
	head=temp->next;
	temp->next=0;
	size--;
	//cout << "dequeue!";
	return temp;
}

int PCBQ::getsize(){//count number of nodes in the queue
		return size;
}